<template>
	<view class="coach">
		<view class="header-bg">
			<custom-navbar :statusBarHeight="statusBarHeight" :navBarHeight="navBarHeight" :windowWidth="windowWidth"
				:color="color" :backgroundColor="backgroundColor" :iconShow="false">
				<!-- <image :src="$IMG_URL('/static/home/scan.png')" mode="" class="scan"></image> -->
			</custom-navbar>
			<!-- 需要添加占位符高度  状态栏高度+导航栏高度（否则下面tab会塌陷）-->
			<view :style="{height: statusBarHeight+navBarHeight+'px'}"></view>
		</view>
		<view class="comlum_box">
			<subscriber :userQuery="managerQuery">
				<view class="cutbtn" @click="MnchangeMy">
					<image :src="$IMG_URL('/static/newVersion/cut.png')" mode="" class="cut"></image>
					回到我的
				</view>
			</subscriber>
			<view class="main_card" v-if="JSON.stringify(managerQuery) !== '{}'">
				<view class="shop_Card">
					<view class="left">
						<image :src="managerQuery.shop_info.category_image" mode="aspectFill" class="icon"></image>
						<view class="title">
							{{managerQuery.shop_info.shop_name}}
						</view>
					</view>
					<view class="right" @click="popupShow = true">
						切换
						<image :src="$IMG_URL('/static/home/indicate.png')" mode="" class="icon1"></image>
					</view>
				</view>
				<view class="salary_box">
					<view class="row_box">
						<view class="top">
							<view class="title" @click="$ROUTELINK('/pageC/stock/final_statement')">
								<view class="size">
									上月结算(元)
								</view>
								<u-icon name="arrow-right" color="#999999" size="14"></u-icon>
							</view>
							<image :src="openEye?$IMG_URL('/static/user/eye.png'):$IMG_URL('/static/user/eyeoff.png')"
								mode="" :class="openEye?'eye':'eyeoff'" @click="openEye = !openEye"></image>
						</view>
						<view class="bottom" v-if="openEye">
							<text class="size1">{{ $FORMATCOST(managerQuery.month_cost).integer }}</text>
							<text class="size2">{{ $FORMATCOST(managerQuery.month_cost).decimal }}</text>
						</view>
						<view class="bottom" v-else>
							<view class="size1">
								****
							</view>
						</view>
					</view>
					<view class="separate">
					</view>
					<view class="row_box">
						<view class="top">
							<view class="title" @click="$ROUTELINK('/pageC/stock/turnover')">
								<view class="size">
									今日营业额(元)
								</view>
								<u-icon name="arrow-right" color="#999999" size="14"></u-icon>
							</view>

						</view>
						<view class="bottom" v-if="openEye">
							<text class="size1">{{ $FORMATCOST(managerQuery.today_cost).integer }}</text>
							<text class="size2">{{ $FORMATCOST(managerQuery.today_cost).decimal }}</text>
						</view>
						<view class="bottom" v-else>
							<view class="size1">
								****
							</view>
						</view>
					</view>
				</view>
			</view>
			<!-- <view class="footbox" v-if="JSON.stringify(managerQuery) !== '{}'">
			
				
			</view> -->
			<!-- <image src="/static/loading/openRoom.png" mode="aspectFill" class="Room" @click.stop="getopenDoor"></image> -->
			<u-toast ref="uToast" />
		</view>
		<view class="empty">

		</view>
		<StockPopup :popupShow="popupShow" @sure="sure" @changeActiveIndex="changeActiveIndex"
			:activeIndex="FieldIndex"></StockPopup>
	</view>
</template>

<script>
	import subscriber from './components/subscriber.vue';
	import StockPopup from './components/stock-popup.vue'
	import CustomNavbar from '@/components/navbar/navbar.vue';
	import {
		atShop,
		stockInfo,
	} from '@/api/stock.js'
	export default {
		props: {
			Field: {
				type: Array,
				default: [],
				required: true
			},
		},
		components: {
			subscriber,
			CustomNavbar,
			StockPopup
		},
		data() {
			return {
				query: {
					shop_id: ''
				},
				// 自定义导航栏
				color: '#ffffff',
				backgroundColor: 'transparent',
				pageTitle: '',
				statusBarHeight: 20,
				navBarHeight: 45,
				windowWidth: 375,
				openEye: false,
				// 切换门店
				popupShow: false,
				FieldIndex: -1,
				managerQuery: {

				}
			}
		},
		mounted() {
			this.getManagerInfo()
		},
		methods: {
			getManagerInfo() {
				stockInfo(this.query).then(({
					data: res
				}) => {
					console.log('res', res);
					if (res.code == 1) {
						this.managerQuery = res.data
					} else {
						let that = this
						uni.showModal({
							title: '温馨提示',
							content: res.msg,
							confirmText: '确认',
							confirmColor: '#73F0EA',
							showCancel: false,
							success: function(res) {
								if (res.confirm) {
									that.$emit(('MnchangeMy'))
								}
							}
						});
					}
				})
			},
			getatShop(e) {
				atShop(e).then(({
					data: res
				}) => {
					console.log('res', res);
					if (res.code == 1) {
						this.managerQuery.shop_info = res.data
					}
				})
			},
			MnchangeMy() {
				this.$emit(('MnchangeMy'))
			},
			// 切换门店
			changeActiveIndex(item, index) {
				this.FieldIndex = index
				this.query.shop_id = item.shop_id
				this.getatShop({
					shop_id: item.shop_id
				})
				this.getManagerInfo()
				this.$forceUpdate()
			},
			sure() {
				this.popupShow = false
			},
		},
		created() {
			// 获取手机系统信息
			const info = uni.getSystemInfoSync()
			// 设置状态栏高度（H5顶部无状态栏小程序有状态栏需要撑起高度）
			this.statusBarHeight = info.statusBarHeight
			this.windowWidth = info.windowWidth
			// 除了h5 app mp-alipay的情况下执行
			// #ifndef H5 || APP-PLUS || MP-ALIPAY
			// 获取胶囊的位置
			const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
			console.log(menuButtonInfo);
			// (胶囊底部高度 - 状态栏的高度) + (胶囊顶部高度 - 状态栏内的高度) = 导航栏的高度
			this.navBarHeight = (menuButtonInfo.bottom - info.statusBarHeight) + (menuButtonInfo.top - info
				.statusBarHeight)
			this.windowWidth = menuButtonInfo.left
			// #endif
		},
	}
</script>

<style lang="scss">
	.empty {
		height: 20rpx;
	}

	.Room {
		width: 136rpx;
		height: 136rpx;
		position: fixed;
		right: 28rpx;
		bottom: 60rpx;
	}

	.scan {
		width: 40rpx;
		height: 40rpx;
		margin-left: 30rpx;
	}

	page {
		background: #e9e9e9;
	}

	.cutbtn {
		width: 90px;
		height: 30px;
		background: rgba(255, 255, 255, 0.5);
		border-radius: 8px;
		font-size: 14px;
		font-family: PingFang SC, PingFang SC-Bold;
		font-weight: 700;
		text-align: left;
		color: #000000;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;

		.cut {
			width: 14px;
			height: 12px;
			margin-right: 5rpx;
		}
	}

	.coach {
		display: flex;
		flex-direction: column;
		align-items: center;

		.header-bg {
			width: 750rpx;
			height: 550rpx;
			background: linear-gradient(180deg, #73F0EA, rgba(255, 255, 255, 0.00));
			display: flex;
			flex-direction: column;
		}

		.comlum_box {
			margin-top: -360rpx;
			width: 750rpx;
			display: flex;
			flex-direction: column;
			align-items: center;

			.main_card {
				display: flex;
				flex-direction: column;
				align-items: center;
				width: 686rpx;

				.shop_Card {
					width: 686rpx;
					height: 120rpx;
					background: rgba(255, 255, 255, 0.5);
					border-radius: 32rpx 32rpx 0rpx 0rpx;
					padding: 26rpx 32rpx 60rpx;
					display: flex;
					flex-direction: row;

					.left {
						display: flex;
						flex-direction: row;
						flex: 1;

						.icon {
							width: 114rpx;
							height: 36rpx;
							margin-right: 12rpx;
						}

						.title {
							font-size: 28rpx;
							font-family: PingFang SC, PingFang SC-Bold;
							font-weight: 700;
							color: #333333;
						}
					}

					.right {
						display: flex;
						flex-direction: row;
						align-items: center;
						font-size: 28rpx;
						font-family: PingFang SC, PingFang SC-Regular;
						font-weight: 400;
						text-align: right;
						color: #666666;

						.icon1 {
							width: 10rpx;
							height: 16rpx;
							margin-left: 8rpx;
						}
					}
				}

				.salary_box {
					margin-top: -22rpx;
					width: 686rpx;
					height: 166rpx;
					background: #ffffff;
					border-radius: 32rpx;
					display: flex;
					flex-direction: row;
					align-items: center;

					.separate {
						width: 0rpx;
						height: 86rpx;
						border: 1rpx solid #e9e9e9;
					}

					.row_box {
						flex: 0.5;
						height: 86rpx;
						display: flex;
						flex-direction: column;
						padding: 0 20rpx 0 42rpx;

						.top {
							display: flex;
							flex-direction: row;
							align-items: center;
							width: 100%;
							margin-bottom: 8rpx;

							.title {
								display: flex;
								flex-direction: row;
								align-items: center;
								flex: 1;

								.size {
									font-size: 24rpx;
									font-family: PingFang SC, PingFang SC-Regular;
									font-weight: 400;
									text-align: left;
									color: #666666;
									margin-right: 11rpx;
								}
							}

							.eye {
								width: 36rpx;
								height: 22rpx;

							}

							.eyeoff {
								width: 34rpx;
								height: 14rpx;
							}
						}

						.bottom {
							display: flex;
							flex-direction: row;
							align-items: baseline;

							.size1 {
								font-size: 36rpx;
								font-family: DIN, DIN-Bold;
								font-weight: 700;
								text-align: left;
								color: #000000;
							}

							.size2 {
								font-size: 24rpx;
								font-family: DIN, DIN-Bold;
								font-weight: 700;
								text-align: left;
								color: #000000;
							}
						}
					}
				}
			}

			.footbox {
				margin-top: 20rpx;
				width: 686rpx;
				background: #ffffff;
				border-radius: 32rpx;
				padding: 0 32rpx;

				.row {
					height: 102rpx;
					width: 100%;
					display: flex;
					flex-direction: row;
					align-items: center;
					padding: 0 14.5rpx;
					border-bottom: 2rpx solid #f8f8f8;

					.tag1 {
						width: 32rpx;
						height: 32rpx;
					}

					.tag2 {
						width: 32rpx;
						height: 36rpx;
					}

					.size {
						font-size: 28rpx;
						font-family: PingFang SC, PingFang SC-Bold;
						font-weight: 700;
						text-align: left;
						color: #333333;
						margin-left: 30rpx;
						flex: 1;
					}
				}
			}
		}
	}
</style>